package com.lipp.example.demos.web.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author mzz
 * @description 响应
 * @since 2024/2/20 10:46
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BaseResponse <T> {

    /**
     * 异常码
     */
    @ApiModelProperty(value = "返回代码;0-成功,500-失败", required = true, notes = "处理成功时为0")
    private int code;

    /**
     * 数据
     */
    @ApiModelProperty(value = "返回数据")
    private T data;

    /**
     * 描述
     */
    @ApiModelProperty(value = "描述信息")
    private String message;

    public static <T> BaseResponse<T> success(T data) {
        return new BaseResponse<>(0, data, "操作成功！");
    }


    public static <T> BaseResponse<T> successMsg(String message) {
        return new BaseResponse<>(0, null, message);
    }

    public static <T> BaseResponse<T> success() {
        return new BaseResponse<>(0, null, "操作成功！");
    }

    public static <T> BaseResponse<T> success(T data, String message) {
        return new BaseResponse<>(0, data, message);
    }

    public static <T> BaseResponse<T> error(String message) {
        return new BaseResponse<>(500, null, message);
    }

}
